package edu.xidian.bdilab.jrbigdata.service.enterprise.checkdemand.impl;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import edu.xidian.bdilab.jrbigdata.controller.response.ResponseResult;
import edu.xidian.bdilab.jrbigdata.mapper.EnterpriseReqMapper;
import edu.xidian.bdilab.jrbigdata.service.enterprise.checkdemand.demandcheckservice;
import org.springframework.beans.factory.annotation.Autowired;
import  edu.xidian.bdilab.jrbigdata.domain.EnterpriseReq;
import  edu.xidian.bdilab.jrbigdata.controller.enterprise.EnterpriseCode;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;
@Service
public class demandcheckserviceimpl  implements demandcheckservice {
    @Autowired
    EnterpriseReqMapper enterpriseMapper;
    @Override
    public ResponseResult demandcheck(String socialCode,
                                      String loanLimit,
                                      String rateLowerLimit,
                                      String rateUpperLimit,
                                      String loanPeriod,
                                      String guaranteeMode)
    {
        QueryWrapper<EnterpriseReq> enterprise_reqWrapper = new QueryWrapper<>();
        enterprise_reqWrapper.eq("fk_social_code",socialCode);
        if(loanLimit!=null&&loanLimit.length()!=0)
        {   enterprise_reqWrapper.eq("loan_limit",Integer.parseInt(loanLimit)); }
        if(rateLowerLimit!=null&&rateLowerLimit.length()!=0)
        {   enterprise_reqWrapper.ge("rate_lower_limit",Double.parseDouble(rateLowerLimit)); }
        if(rateUpperLimit!=null&&rateUpperLimit.length()!=0)
        {   enterprise_reqWrapper.le("rate_upper_limit",Double.parseDouble(rateUpperLimit)); }
        if(loanPeriod!=null&&loanPeriod.length()!=0)
        {   enterprise_reqWrapper.like("loan_period",Integer.parseInt(loanPeriod)); }
        if(guaranteeMode!=null&&guaranteeMode.length()!=0)
        {   enterprise_reqWrapper.eq("guarantee_mode",Integer.parseInt(guaranteeMode)); }
        ResponseResult responseResult=new ResponseResult();
        List<EnterpriseReq> list=enterpriseMapper.selectList(enterprise_reqWrapper);
        if(list.size()==0)
        {
            responseResult.setSuccess(Boolean.FALSE);
            responseResult.setCode(EnterpriseCode.Demand_CHECK_Failed.getCode());
            responseResult.setMessage(EnterpriseCode.Demand_CHECK_Failed.getMessage());
        }
       else
        {
            responseResult.setData(list);
            responseResult.setSuccess(Boolean.TRUE);
            responseResult.setCode(EnterpriseCode.Demand_CHECK_SUCCESS.getCode());
            responseResult.setMessage(EnterpriseCode.Demand_CHECK_SUCCESS.getMessage());
        }
        return  responseResult;
    }
}
